home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / misc / emu / atari800_tr.lzh / patch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-17  |  4.2 KB  |  209 lines

  1. /****************************************************************
  2.  ** patch.c                                                    **
  3.  **                                                            **
  4.  ** Install and handle OS patches V 0.9.1, thor                **
  5.  ****************************************************************/   
  6.  
  7. #include <stdio.h>
  8.  
  9. #include "rt-config.h"
  10. #include "atari.h"
  11. #include "mem.h"
  12. #include "sio.h"
  13. #include "devices.h"
  14. #include "cpu.h"
  15. #include "patch.h"
  16.  
  17.  
  18. const unsigned short    o_open = 0;
  19. const unsigned short    o_close = 2;
  20. const unsigned short    o_read = 4;
  21. const unsigned short    o_write = 6;
  22. const unsigned short    o_status = 8;
  23. /* const unsigned short    o_special = 10; */
  24. const unsigned short    o_init = 12;
  25.  
  26. static char *rcsid = "$Id: patch.c,v 1.00 1998/02/17 thor";
  27.  
  28. static void add_esc (ATPtr address, int esc_code)
  29. {
  30.   RomSet(address,0xf2);
  31.   RomSet(address+1,esc_code);
  32.   RomSet(address+2,0x60);
  33. }
  34.  
  35. static void SetupHatabs(ATPtr addr)
  36. {
  37. int i;
  38. ATPtr devtab;
  39. int entry;
  40.  
  41.   for (i=0;i<5;i++)
  42.     {
  43.       devtab = RomDGet(addr+1);
  44.       switch (RomGet(addr))
  45.     {
  46.     case 'P' :
  47.       entry = RomDGet(devtab+o_open);
  48.       add_esc (entry+1, ESC_PHOPEN);
  49.       entry = RomDGet(devtab+o_close);
  50.       add_esc (entry+1, ESC_PHCLOS);
  51. /*
  52.       entry = RomDGet(devtab+o_read);
  53.       add_esc (entry+1, ESC_PHREAD);
  54. */
  55.       entry = RomDGet(devtab+o_write);
  56.       add_esc (entry+1, ESC_PHWRIT);
  57.       entry = RomDGet(devtab+o_status);
  58.       add_esc (entry+1, ESC_PHSTAT);
  59. /*
  60.       entry = RomDGet(devtab+o_special);
  61.       add_esc (entry+1, ESC_PHSPEC);
  62. */
  63.       RomSet(devtab+o_init,0xd2);
  64.       RomSet(devtab+o_init+1,ESC_PHINIT);
  65.       break;
  66.     case 'C' :
  67.       RomSet(addr,'H');
  68.       entry = RomDGet(devtab+o_open);
  69.       add_esc (entry+1, ESC_HHOPEN);
  70.       entry = RomDGet(devtab+o_close);
  71.       add_esc (entry+1, ESC_HHCLOS);
  72.       entry = RomDGet(devtab+o_read);
  73.       add_esc (entry+1, ESC_HHREAD);
  74.       entry = RomDGet(devtab+o_write);
  75.       add_esc (entry+1, ESC_HHWRIT);
  76.       entry = RomDGet(devtab+o_status);
  77.       add_esc (entry+1, ESC_HHSTAT);
  78.       break;
  79.     case 'E' :
  80. #ifdef BASIC
  81.       entry = RomDGet(devtab+o_open);
  82.       add_esc (entry+1, ESC_E_OPEN);
  83.       entry = RomDGet(devtab+o_read);
  84.       add_esc (entry+1, ESC_E_READ);
  85.       entry = RomDGet(devtab+o_write);
  86.       add_esc (entry+1, ESC_E_WRITE);
  87. #endif
  88.       break;
  89.     case 'S' :
  90.       break;
  91.     case 'K' :
  92. #ifdef BASIC
  93.       entry = RomDGet(devtab+o_read);
  94.       add_esc (entry+1, ESC_K_READ);
  95. #endif
  96.       break;
  97.     default :
  98.       break;
  99.     }
  100.  
  101.       addr += 3;    /* Next Device in HATABS */
  102.     }
  103. }
  104.  
  105. void PatchOsXL(void)
  106. {
  107.  
  108.   if (enable_sio_patch)
  109.     add_esc (0xe459, ESC_SIOV);
  110.  
  111.   RomSet(0xc314,0x8e);
  112.   RomSet(0xc315,0xff);
  113.   RomSet(0xc319,0x8e);
  114.   RomSet(0xc31a,0xff);
  115.   
  116.   SetupHatabs(0xc42e);
  117. }
  118.  
  119. void PatchOsA (void)
  120. {
  121.   if (enable_sio_patch)
  122.     add_esc (0xe459,ESC_SIOV);
  123.  
  124.   SetupHatabs(0xf0e3);
  125. }
  126.  
  127. void PatchOsB (void)
  128. {
  129.   if (enable_sio_patch)
  130.     add_esc (0xe459,ESC_SIOV);
  131.  
  132.   SetupHatabs(0xf0e3);
  133. }
  134.  
  135. void Escape (int esc_code)
  136. {
  137.  
  138.   switch (esc_code)
  139.     {
  140.     case ESC_SIOV :
  141.       SIO ();
  142.       break;
  143.     case ESC_K_OPEN :
  144.     case ESC_K_CLOSE :
  145.     case ESC_K_READ :
  146.     case ESC_K_WRITE :
  147.     case ESC_K_STATUS :
  148.     case ESC_K_SPECIAL :
  149.       K_Device (esc_code);
  150.       break;
  151.     case ESC_E_OPEN :
  152.     case ESC_E_READ :
  153.     case ESC_E_WRITE :
  154.       E_Device (esc_code);
  155.       break;
  156.     case ESC_PHOPEN :
  157.       Device_PHOPEN ();
  158.       break;
  159.     case ESC_PHCLOS :
  160.       Device_PHCLOS ();
  161.       break;
  162.     case ESC_PHREAD :
  163.       Device_PHREAD ();
  164.       break;
  165.     case ESC_PHWRIT :
  166.       Device_PHWRIT ();
  167.       break;
  168.     case ESC_PHSTAT :
  169.       Device_PHSTAT ();
  170.       break;
  171.     case ESC_PHSPEC :
  172.       Device_PHSPEC ();
  173.       break;
  174.     case ESC_PHINIT :
  175.       Device_PHINIT ();
  176.       break;
  177.     case ESC_HHOPEN :
  178.       Device_HHOPEN ();
  179.       break;
  180.     case ESC_HHCLOS :
  181.       Device_HHCLOS ();
  182.       break;
  183.     case ESC_HHREAD :
  184.       Device_HHREAD ();
  185.       break;
  186.     case ESC_HHWRIT :
  187.       Device_HHWRIT ();
  188.       break;
  189.     case ESC_HHSTAT :
  190.       Device_HHSTAT ();
  191.       break;
  192.     case ESC_HHSPEC :
  193.       Device_HHSPEC ();
  194.       break;
  195.     case ESC_HHINIT :
  196.       Device_HHINIT ();
  197.       break;
  198.     case ESC_BREAK  :
  199.     case ESC_MONITOR :
  200.       Atari800_Exit (TRUE, 0);
  201.       break;
  202.     default         :
  203.       printf ("Invalid ESC Code %x at Address %x\n",
  204.           esc_code, regPC - 2);
  205.       Atari800_Exit (TRUE, 1);
  206.       break;
  207.     }
  208. }
  209.